package com.travel.mapper.content;

import com.travel.model.entity.content.Tag;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;
//标签mapper 查询标签 插入标签 
@Mapper
@Repository("tagMapperMyBatis")
public interface TagMapper {
    
    @Select("SELECT * FROM tags WHERE id = #{id}")
    Optional<Tag> findById(@Param("id") Long id);
    
    @Select("SELECT * FROM tags WHERE name = #{name}")
    Optional<Tag> findByName(@Param("name") String name);
    
    @Select("SELECT t.* FROM tags t " +
            "INNER JOIN guide_tags gt ON t.id = gt.tag_id " +
            "WHERE gt.guide_id = #{guideId}")
    List<Tag> findByGuideId(@Param("guideId") Long guideId);
    
    @Insert("INSERT INTO tags (name, created_time) VALUES (#{name}, #{createdTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void save(Tag tag);
    
    @Delete("DELETE FROM tags WHERE id = #{id}")
    int delete(Tag tag);
    
    @Select("SELECT * FROM tags")
    List<Tag> findAll();
    
    @Select("SELECT * FROM tags WHERE name LIKE CONCAT('%', #{keyword}, '%')")
    List<Tag> searchTags(@Param("keyword") String keyword);
} 